package stickyhand.ui;

import java.awt.Dimension;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

import stickyhand.NZB;

public class SHGetInfoFile extends JScrollPane {
	JTable tableP;
	NZB nzb_info;
	
	public SHGetInfoFile(NZB nzb_info) {
		super(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 
						JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		this.nzb_info = nzb_info;
		this.setName("Files");
		
		tableP = new JTable(new SHGetInfoTableModel(nzb_info));
		tableP.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		this.setViewportView(tableP);
		this.setVisible(true);
	}

	public void updateSize(Dimension size) {
		Float fileW, sizeW, segmentsW, posterW, dateW, groupsW;
		TableColumn column = null;
		
		fileW 		= new Float(0.35);
		dateW 		= new Float(0.15);
		sizeW 		= new Float(0.1);
		segmentsW 	= new Float(0.1);
		posterW 	= new Float(0.15);
		groupsW 	= new Float(0.15);
		
		Dimension newSize = new Dimension((int)size.getWidth() - 45, 
				(int)size.getHeight() - 45);
		
		this.setPreferredSize(newSize);
		tableP.setPreferredSize(newSize);
		tableP.setPreferredScrollableViewportSize(tableP.getPreferredSize());
		
		for (int i = 0; i < 6; i++) {
			column = tableP.getColumnModel().getColumn(i);
			switch (i) {
			case 0:		/* name */
				column.setPreferredWidth(Math.round((float)(fileW * newSize.getWidth())));
				break;
			case 1:		/* date */
				column.setPreferredWidth(Math.round((float)(dateW * newSize.getWidth())));
				break;
			case 2:		/* size */
				column.setPreferredWidth(Math.round((float)(sizeW * newSize.getWidth())));
				break;
			case 3:		/* segments */
				column.setPreferredWidth(Math.round((float)(segmentsW * newSize.getWidth())));
				break;
			case 4:		/* poster */
				column.setPreferredWidth(Math.round((float)(posterW * newSize.getWidth())));
				break;
			case 5:		/* groups */
				column.setPreferredWidth(Math.round((float)(groupsW * newSize.getWidth())));
				break;
			}
		}
	}
}
